import { request } from './request'

/**
 * 题库相关的API请求
 */

// 获取题库中的题目列表
export const getLibraryQuestions = (libraryId) => {
  return request.get('/libraries/getLibraryQuestions', { libraryId })
}
// 添加题目到题库（单个或批量）[1],[1,2,3..]
export const addQuestionToLibrary = (libraryId, questionIds) => {
  return request.get('/libraries/addQuestion', { libraryId, questionIds })
}
// 从题库中移除题目（单个或批量）[1],[1,2,3..]
export const removeQuestionFromLibrary = (libraryId, questionIds) => {
  return request.get('/libraries/deleteQuestion', { "libraryId": libraryId, "questionIds": questionIds })
}

/**
 * 题目相关的API请求
 */

export const getQuestions = (ids) => {
  return request.get(`/libraries/questions?ids=${ids}`)
}
// 保存题目（单个或批量）并添加到题库
export const saveQuestions = (libraryId, questions) => {
  return request.post(`/questions/save?libraryId=${libraryId}`, questions,
    {
      'Content-Type': 'application/json'
    }
  )
}
// 更新题目
export const updateQuestion = (id, data) => {
  return request.post(`/questions/update?id=${id}`, data,
    {
      'Content-Type': 'application/json'
    }
  )
}

// 删除题目
export const deleteQuestion = (id) => {
  return request.post(`/questions/delete?id=${id}`)
}

// 获取单个题目详情
export const getQuestionDetail = (id) => {
  return request.get(`/questions/${id}`)
}

// 获取多个题目详情
export const getQuestionsByIds = (ids) => {
  return request.post('/questions/batch', ids)
} 